using System.Threading;
using Unity.Burst;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs;

namespace Tutorial6_InterlockedJob
{
    [BurstCompile]
    public unsafe struct InterlockedParallelJob : IJobFor
    {
        [NativeDisableContainerSafetyRestriction] // 禁用Container的检查
        [ReadOnly]
        public NativeArray<long> inputData;

        [NativeDisableUnsafePtrRestriction]  // 禁用ptr的竞争检查
        [WriteOnly]public long* outputSumData;
        
        public void Execute(int index)
        {
            Interlocked.Add(ref UnsafeUtility.AsRef<long>(outputSumData), inputData[index]);
        }
    }
}
